a = {'x': 1, 'z': 3}
b = {'y': 2, 'z': 4}

from collections import ChainMap

c = ChainMap(a, b)

values = ChainMap()
values['x'] = 1
values = values.new_child()  # 新增child
values['x'] = 2
values = values.new_child()
values['x'] = 3
values = values.parents  # 删除子集

# 作为chainmap的替换，但是如果a中的数据发生变化，merged不受影响
merged = dict(b)
merged.update(a)

# 又比如
a = {'x': 1, 'z': 3}
b = {'y': 2, 'z': 4}
merged = ChainMap(a, b)
a['x'] = 11
print(merged)  # 会发生变化
